#include <bits/stdc++.h>
using namespace std;
int n, dt, et, vis[500005];
vector<int> ed[500005];

inline void dfs(int i) {
	if (vis[i]) return;
	vis[i] = 1; ++dt;
	for (auto j : ed[i]) {
		++et;
		dfs(j);
	}
}


int main() {
	freopen("pairint.in", "r", stdin); freopen("pairint.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int a, b;
		cin >> a >> b;
		ed[a].push_back(b);
		ed[b].push_back(a);
	}
	int ans = 0;
	for (int i = 1; i <= 500000; ++i) {
		if (!vis[i]) {
			dt = et = 0;
			dfs(i);
			et /= 2;
			if (et >= dt) {
				ans += dt;
			} else ans += dt - 1;
		}
	}
	cout << ans << "\n";
}
